/*
 * Created on Feb 15, 2005
 * Created by dfhuynh
 */
package edu.mit.simile.longwell.ui.command;

import javax.servlet.ServletException;

import org.apache.log4j.Logger;
import org.apache.velocity.VelocityContext;

import com.hp.hpl.jena.rdf.model.Resource;

import edu.mit.simile.longwell.ui.FlairMessage;
import edu.mit.simile.longwell.ui.InjectionManager;

/**
 * @author dfhuynh
 */
public class FocusCommand extends CommandBase {
	final static private Logger s_logger = Logger.getLogger(FocusCommand.class);

	/**
	 * @param injectionManager
	 */
	public FocusCommand(InjectionManager injectionManager) {
		super(injectionManager);
	}

	/* (non-Javadoc)
	 * @see edu.mit.simile.flair.IFlairCommand#execute(edu.mit.simile.flair.FlairMessage)
	 */
	public void execute(FlairMessage msg) throws ServletException {
		try {
			VelocityContext vcContext = createContext(msg);

			String pseudoURI = msg.m_query.getFirstParamValue("pseudoURI");
			Resource r = msg.getProfile().getSchemaModel().pseudoURIToResource(pseudoURI);

			vcContext.put("object", r);

			msg.m_ve.mergeTemplate(
				"templates/commands/focus.vt",
				vcContext,
				msg.m_response.getWriter());
		} catch (Throwable e) {
			s_logger.error(e);
			e.printStackTrace();
		}
	}

}
